home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 028a / arcutils.zip / CONVERT.C next >
C/C++ Source or Header  |  1989-04-20  |  5KB  |  178 lines

  1. #include <dos.h>
  2. #include <stdio.h>
  3. #include <dir.h>
  4. #include <stdlib.h>
  5.  
  6. main(argc,argv)
  7. int argc;
  8. char *argv[];
  9. {
  10.    char string[80],string2[80],string3[15],ext[20][5],method[20][50],
  11.       ext2[20][5],method2[20][50];
  12.    FILE *file;
  13.    int i,j,type,done,number=0,number2=0;
  14.    struct ffblk ffblk;
  15.  
  16.    typedef struct file_stack FILES;
  17.    struct file_stack {              /* holds a directory listing */
  18.       char string[13];
  19.       FILES *next;
  20.    };
  21.  
  22.    FILES *head,*tail,*temp_hold;
  23.  
  24.    printf("Archive Format Converter.\n");
  25.    printf("Ver 1.05\nDave Harris  1:302/5\n\n");
  26.  
  27.  
  28.    if (argc==1)
  29.       strcpy(string3,"*.*");
  30.    else
  31.       strcpy(string3,argv[1]);
  32.  
  33.    if (!strstr(string3,"."))
  34.       strcat(string3,".*");
  35.  
  36. /*************************************************************************/
  37. /* open the configuration file, look through path if necessary */
  38.  
  39.    file=fopen("convert.cfg","r");
  40.    if (file==NULL) {                     /* ok, its not in the current */
  41.       int pathpos=0,dirpos;              /* directory so lets trudge through */
  42.       char path[200],directory[80];      /* the PATH */
  43.       strcpy(path,getenv("PATH"));       
  44.  
  45.       while (1) {
  46.          dirpos=0;
  47.          while (path[pathpos]!=';' && path[pathpos]!=NULL) {
  48.             directory[dirpos++]=path[pathpos++];
  49.          }
  50.          if (path[pathpos]==NULL) {        /* we have looked through the whole
  51.                                               PATH without success */
  52.             printf("Can't find CONVERT.CFG\n");
  53.             exit(1);
  54.          }
  55.          pathpos++;     /* get us over the ; */
  56.  
  57.          if (directory[dirpos-1]!='\\')
  58.             directory[dirpos++]='\\';
  59.          directory[dirpos]=NULL;
  60.          strcat(directory,"convert.cfg");
  61.          file=fopen(directory,"r");
  62.          if (file!=NULL)
  63.             break;
  64.          else
  65.             fclose(file);
  66.       }
  67.    }
  68. /**********************************************************************/
  69. /* parse the configuration file for the control info */
  70.  
  71.    while (fscanf(file,"%s",string)!=EOF) {
  72.       if (stricmp(string,"U")==0) {
  73.          fscanf(file,"%s",ext[number]);
  74.          type=0;
  75.          while (1) {
  76.             i=getc(file);
  77.             if (i=='\n' || i==EOF) {
  78.                method[number][type]=NULL;
  79.                number++;
  80.                break;
  81.             }
  82.             else
  83.                method[number][type++]=i;
  84.          }
  85.          strupr(ext[number-1]);
  86.       }
  87.       else  {
  88.          fscanf(file,"%s",ext2[number2]);
  89.          type=0;
  90.          while (1) {
  91.             i=getc(file);
  92.             if (i=='\n' || i==EOF) {
  93.                method2[number2][type]=NULL;
  94.                number2++;
  95.                break;
  96.             }
  97.             else
  98.                method2[number2][type++]=i;
  99.          }
  100.          strupr(ext2[number2-1]);
  101.       }
  102.    }
  103. /********************************************************************/
  104. /* get all the file names and put them on the queue */
  105.  
  106.    done=findfirst(string3,&ffblk,0);
  107.    if (done)
  108.       exit(0);
  109.  
  110.    system("MD conv89");      /* temporary storage */
  111.  
  112.    head=(FILES*)malloc(sizeof(FILES));
  113.    strcpy(head->string,ffblk.ff_name);
  114.    head->next=NULL;
  115.    tail=head;
  116.    while (!done) {
  117.       done=findnext(&ffblk);
  118.       if (done)
  119.          break;
  120.       temp_hold=(FILES*)malloc(sizeof(FILES));
  121.       strcpy(temp_hold->string,ffblk.ff_name);
  122.       tail->next=temp_hold;
  123.       tail=temp_hold;
  124.       tail->next=NULL;
  125.    }
  126. /********************************************************************/
  127.  
  128.    while (head!=NULL)  {
  129.       strcpy(string,head->string);
  130.       for (i=0;i<number;i++) {
  131.          if (strstr(string,ext[i])!=NULL) {
  132.             printf("Converting %s\n",string);
  133.             sprintf(string2,"RED %s conv89",string);
  134.             system(string2);
  135.             system("CD conv89");
  136.             sprintf(string2,method[i],string);
  137.             system(string2);
  138.             remove(string);
  139.  
  140.             for (i=0;i<number2;i++) {
  141.                j=0;
  142.                while (1) {
  143.                   if (string[j]=='.') {
  144.                      string[j]=NULL;
  145.                      strcat(string,ext2[i]);
  146.                      break;
  147.                   }
  148.                   j++;
  149.                }
  150.                sprintf(string2,method2[i],string);
  151.                system(string2);
  152.                sprintf(string2,"RED %s ..",string);
  153.                system(string2);
  154.             }
  155.  
  156.             done=findfirst("*.*",&ffblk,0);    /* del *.*  */
  157.             if (done)
  158.                break;
  159.             while (!done) {
  160.                remove(ffblk.ff_name);
  161.                done=findnext(&ffblk);
  162.             }
  163.             system("CD ..");
  164.             break;
  165.  
  166.          }
  167.  
  168.  
  169.       }
  170.       temp_hold=head;
  171.       head=head->next;
  172.       free(temp_hold);          /* clean up behind */
  173.    }
  174.    system("RD conv89");
  175.  
  176. }
  177.  
  178.